package com.icehand.sentinel.config;

import com.alibaba.csp.sentinel.datasource.ReadableDataSource;
import com.alibaba.csp.sentinel.datasource.nacos.NacosDataSource;
import com.alibaba.csp.sentinel.init.InitFunc;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.nacos.api.PropertyKeyConst;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Properties;

/**
 * @author icehand
 * @date 2020年6月19日
 */
public class DataSourceInitFunc implements InitFunc {
    private String nacosConfigAddr = "";
    private String namespace ;
    private String groupId;
    private String dataId;

    @Override
    public void init() {
//        Properties properties = new Properties();
//        properties.put(PropertyKeyConst.SERVER_ADDR, nacosConfigAddr);
//        properties.put(PropertyKeyConst.NAMESPACE, namespace);
//        ReadableDataSource<String, List<FlowRule>> flowRuleDataSource = new NacosDataSource<>(properties, groupId, dataId,
//            source -> JSON.parseObject(source, new TypeReference<List<FlowRule>>() {}));
//        FlowRuleManager.register2Property(flowRuleDataSource.getProperty());
    }
}